using System.CodeDom;
using System.Collections.Generic;
using InterfaceWeaver.AopCore;
using Roslyn.Compilers.CSharp;

namespace InterfaceWeaver.CustomTool
{
    public class WeaverOptionsAspectHandler : AspectHandlerBase<WeaverOptionsAttribute>
    {
        public override void HandleOnInterface(AspectDispatcher context, AttributeSyntax attributeSyntax, InterfaceDeclarationSyntax interfaceDeclarationSyntax)
        {
            var forceInitialization = attributeSyntax.HasParameter("ForceInitialization") 
                && attributeSyntax.GetParameterValue<bool>("ForceInitialization");

            var skipConstructorDeclaration = attributeSyntax.HasParameter("SkipConstructorDeclaration")
                && attributeSyntax.GetParameterValue<bool>("SkipConstructorDeclaration");

            if(forceInitialization)
            {
                context.WeavedCodeContext.CurrentTypeDeclaration.EnsureInitializeComponentMethodDeclaration(!skipConstructorDeclaration);
                context.WeavedCodeContext.CurrentTypeDeclaration.EnsureInitializeCommandsMethodDeclaration(!skipConstructorDeclaration);
            }
        }
    }
}